//	uView 将它所有的工具类，全都放在了 uni.$u 这个对象上
const http = uni.$u.http

// 获取分类信息
const getClassify = () => http.get('/api/classify/get', {
	params: {
		projectId: 170
	}
})

// 根据分类id查找博客
const getBlogByClassify = (id) => http.get('/api/blog/searchByClassifyId', {
	params: {
		id,
		projectId: 170
	}
})

// 根据关键词搜索博客
const getBlogByKeywords = (keyword) => http.get('/api/blog/searchByInput', {
	params: {
		keyword,
		projectId: 170
	}
})

// 创建博客
const createBlog = (data, token) => http.post('/api/blog/create', data, {
	header: {
		"x-token": token
	}
})

// 根据id查找博客
const blogId = (id) => http.get('/api/blog/search', {
	params: {
		id,
		projectId: 170
	}
})

// 创建评论
const addComment = (blogId, content, token) => http.post('/api/comment/create', {
	blogId,
	projectId: 170,
	content
}, {
	header: {
		"x-token": token
	}
})

// 评论下创建评论
const addsonComment = (blogId, content,parentCommentId,token) => http.post('/api/comment/create', {
	blogId,
	projectId: 170,
	content,
	parentCommentId
}, {
	header: {
		"x-token": token
	}
})

// 获取当前博客的评论
const getComment = (id, limit, offset) => http.get('/api/comment/get', {
	params: {
		id,
		projectId: 170,
		limit,
		offset
	}
})

//	用户模块--登录
const login = (data) => http.post('/api/user/login', data)

// 用户注册
const register = (form) => http.post('api/user/register', {
	"phone": form.phone,
	"name": form.name,
	"password": form.password,
	"projectId": "170"
})

// 获取用户信息
const message = (id, token) => http.get('/api/user/searchUser', {
	params: {
		id,
		projectId: 170
	},
	header: {
		"x-token": token
	}
})

// 获取用户自己博客
const myBlog = (limit, offset, token) => http.get('/api/blog/getMyBlog', {
	params: {
		projectId: 170,
		limit,
		offset
	},
	header: {
		"x-token": token
	}
})

// 获取用户关注
const myAttention = (token) => http.get('/api/user/getLikeUser', {
	header: {
		"x-token": token
	}
})

// 获取点赞过的博客	
const praise = (token) => http.get('/api/user/getLikeBlog', {
	header: {
		"x-token": token
	}
})

// 点赞/取消点赞博客评论
const likeComment = (commentId, blogId,token) => http.post('/api/comment/like', {
	commentId,
	blogId,
	"projectId": 170
}, {
	header: {
		"x-token": token
	}
})

// 关注/取消关注博主
const attentionUser = (id,token) => http.post('/api/user/follow',{
	id,
	"projectId": 170
}, {
	header: {
		"x-token": token
	}
})

// 点赞/取消点赞博客
const likeBlog = (id,token) => http.post('/api/blog/likeBlog',{
	id,
	"projectId": 170
}, {
	header: {
		"x-token": token
	}
})

// 修改用户信息
const changeMeans = (name, cover, motto, token) => http.put('/api/user/edit', {
	"name": name,
	"avatar": cover,
	"desc": motto,
	"projectId": 170
}, {
	header: {
		"x-token": token
	}
})


// 判断手机号码是否注册	
const repeat = phone => http.post('/api/user/isRegister', {
	phone
})


//	文件模块
const upload = (data, token) => http.upload('/api/imgUpload', {
	header: {
		"x-token": token
	},
	formData: {
		file: data
	}
})

export {
	getClassify,
	getBlogByClassify,
	getBlogByKeywords,
	createBlog,
	login,
	upload,
	register,
	repeat,
	message,
	myBlog,
	myAttention,
	praise,
	changeMeans,
	blogId,
	addComment,
	getComment,
	likeComment,
	attentionUser,
	likeBlog,
	addsonComment
}
